package com.gitee.slowcreator.module.http.request.intface;

import com.gitee.slowcreator.http.annotation.*;
import com.gitee.slowcreator.http.enums.RequestType;
import com.gitee.slowcreator.http.exception.HttpRequestException;
import com.gitee.slowcreator.http.params.*;
import com.gitee.slowcreator.http.parser.json.JsonHttpReturnParser;

import java.util.Map;
import java.util.Set;

/**
 * @author zxw
 * @date 2023/1/7 上午11:46
 */
@HttpInterface(desc = "测试接口")
public interface ITestHttpRequest {

    /**
     * 测试get请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试GET",
            url = "http://127.0.0.1:8080/annotationHttp/testGet",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000
    )
    ScReturn testGet(@HttpHeader Map<String, String> header,
                     @HttpParams Map<String, String[]> params,
                     @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试post请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试POST",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST
    )
    ScReturn testPost(@HttpHeader Map<String, String> header,
                      @HttpParams Map<String, String[]> params,
                      @HttpReturnHeader Set<String> returnHeader,
                      ScBody body);

    /**
     * 测试put请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试PUT",
            url = "http://127.0.0.1:8080/annotationHttp/testPut",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.PUT
    )
    ScReturn testPut(@HttpHeader Map<String, String> header,
                     @HttpParams Map<String, String[]> params,
                     @HttpReturnHeader Set<String> returnHeader,
                     ScBody body);

    /**
     * 测试delete请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试DELETE",
            url = "http://127.0.0.1:8080/annotationHttp/testDelete",
            timeout = 10000,
            requestType = RequestType.DELETE
    )
    ScReturn testDelete(@HttpHeader Map<String, String> header,
                        @HttpParams Map<String, String[]> params,
                        @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试上传请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param scMultipart
     * @return
     */
    @HttpClient(
            desc = "测试Upload",
            url = "http://127.0.0.1:8080/annotationHttp/testUpload",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST,
            isMultipart = true
    )
    ScReturn testUpload(@HttpHeader Map<String, String> header,
                        @HttpParams Map<String, String[]> params,
                        @HttpReturnHeader Set<String> returnHeader,
                        ScMultipart scMultipart);

    /**
     * 测试下载请求 使用 byte[] 接收数据
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试DownloadByte",
            url = "http://127.0.0.1:8080/annotationHttp/testDownload",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.GET
    )
    ScReturn testDownloadByte(@HttpHeader Map<String, String> header,
                              @HttpParams Map<String, String[]> params,
                              @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试下载请求 文件直接写入本地
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试DownloadWriteLocal",
            url = "http://127.0.0.1:8080/annotationHttp/testDownload",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.GET,
            download = true,
            downloadLocal = true,
            downloadLocalFilename = "/home/manjaro/test_file/annotation_http/test10.jpg"
    )
    ScReturn testDownloadWriteLocal(@HttpHeader Map<String, String> header,
                                    @HttpParams Map<String, String[]> params,
                                    @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试json解析器
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试POST",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST,
            enhanceAfter = JsonHttpReturnParser.class
//            retry = @Retry(
//                    open = true,
//                    retryTimes = 3
//            )
    )
    ScReturn testJsonParse(@HttpHeader Map<String, String> header,
                           @HttpParams Map<String, String[]> params,
                           @HttpReturnHeader Set<String> returnHeader,
                           ScBody body);

    /**
     * 测试ScUnionParams直接请求
     *
     * @param unionParams
     * @return
     */
    @HttpClient(
            desc = "测试UNION",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST
    )
    ScReturn testUnion(ScUnionParams unionParams);

    /**
     * 测试无注解请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试NoAnnotation",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST
    )
    ScReturn testNoAnnotation(ScHeader header,
                              ScParams params,
                              ScReturnHeader returnHeader,
                              ScBody body);

    /**
     * 测试url覆盖
     *
     * @param url
     * @return
     */
    @HttpClient(desc = "测试GET", url = "666")
    ScReturn testUrlChange(@HttpUrl String url);

}
